<!-- <template>
  <s-layout
    title="我的"
    tabbar="/pages/index/user"
    navbar="custom"
    :bgStyle="template.style?.background"
    :navbarStyle="template.style?.navbar"
    onShareAppMessage
    :showFloatButton="true"
  >
    <s-block
      v-for="(item, index) in template.data"
      :key="index"
      :styles="item.style"
    >
      <s-block-item :type="item.type" :data="item.data" :styles="item.style" />
    </s-block>
  </s-layout>
</template>

<script setup>
import { computed } from "vue";
import { onShow, onPageScroll, onPullDownRefresh } from "@dcloudio/uni-app";
import sheep from "@/sheep";
// import {
// 	nextTick
// } from '@/dist/build/mp-weixin/common/vendor';

// 隐藏原生tabBar
uni.hideTabBar();

const template = computed(() => sheep.$store("app").template.user);

const isLogin = computed(() => sheep.$store("user").isLogin);
// console.log(1111, isLogin)
onShow(() => {
  sheep.$store("user").updateUserData();
});

onPullDownRefresh(() => {
  sheep.$store("user").updateUserData();
  setTimeout(function () {
    uni.stopPullDownRefresh();
  }, 800);
});

onPageScroll(() => {});
</script> -->

<template>
  <s-layout
    title="我的"
    tabbar="/pages/index/user"
    navbar="custom"
    :bgStyle="template.style?.background"
    :navbarStyle="template.style?.navbar"
    onShareAppMessage
    :showFloatButton="true"
  >
    <view class="basemap"></view>
    <s-block
      v-for="(item, index) in template.data"
      :key="index"
      :styles="item.style"
      class="shadow-effect"
    >
      <view
        v-if="item.type == 'menuGrid'"
        style="
          font-size: 30rpx;
          font-weight: 700;
          margin-left: 20rpx;
          margin-top: 14rpx;
        "
        >菜单栏</view
      >
      <s-block-item
        :type="item.type"
        :data="item.data"
        :styles="item.style"
        @click="handleBlockItemClick(item)"
      />
    </s-block>
    <view
      v-if="userInfo.employee == 1"
      style="
        width: 90%;
        background-color: white;
        margin: auto;
        padding: 20rpx;
        border-radius: 20rpx;
      "
      @click="sheep.$router.go('/pages/shoopbackground/index')"
      >工作台</view
    >
  </s-layout>
</template>

<script setup>
import { computed, ref } from "vue";
import { onShow, onPullDownRefresh, onLoad } from "@dcloudio/uni-app";
import sheep from "@/sheep";
import { showAuthModal } from "@/sheep/hooks/useModal";

// 隐藏原生tabBar
uni.hideTabBar();

const userInfo = computed(() => sheep.$store("user").userInfo);

const template = computed(() => sheep.$store("app").template.user);
const isLogin = computed(() => sheep.$store("user").isLogin);

console.log("kankan", userInfo.value);

const phone = ref();

onShow(() => {
  // 用户登录但是没有手机号的
  // if (phone.value == null && isLogin.value) {
  //   console.log("需要弹框");
  //   handleLogin();
  // }

  sheep.$store("user").updateUserData();
});

onLoad(() => {
  // 用户修改头像
  console.log("userInfo:", userInfo.value.nickname);
  if (userInfo.value.nickname == "微信用户") {
    uni.showModal({
      title: "提示",
      content: "点击右侧白色图标修改昵称头像",
      showCancel: false,
    });
  }
});

onPullDownRefresh(() => {
  sheep.$store("user").updateUserData();
  setTimeout(function () {
    uni.stopPullDownRefresh();
  }, 800);
});

// 处理 s-block-item 的点击事件
function handleBlockItemClick(item) {
  if (!isLogin.value) {
    // 用户未登录，弹出登录框
    handleLogin();
  } else {
    // 用户已登录，执行 s-block-item 的默认行为

    sheep.$router.go(item.data.path, item.data.query);
  }
}

// 弹出登录框
function handleLogin() {
  if (sheep.$platform.name === "WechatMiniProgram") {
    showAuthModal("wechatMiniLogin");
  } else {
    showAuthModal("smsLogin");
  }
}
</script>

<style>
.basemap {
  background: linear-gradient(to bottom, #fe5348, #fd8154);
  position: absolute;
  height: 450rpx;
  width: 100%;
  z-index: -10;
}
</style>
